package kr.or.kosta.otr.persistence.board;

import java.sql.SQLException;
import java.util.ArrayList;

import javax.annotation.Resource;

import kr.or.kosta.otr.vo.BoardVO;

import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;

@Repository("BoardDao")
public class BoardDaoImpl implements BoardDao{
	
	@Resource(name="sqlMapClient")
	private SqlMapClient sqlMapClient;

	@Override
	public int writeBoard(BoardVO vo) throws SQLException {
		return (int) sqlMapClient.insert("Board.writeBoard", vo);
	}

	@Override
	public void updateBoard(BoardVO vo) throws SQLException {
		sqlMapClient.update("Board.updateBoard", vo);
	}

	@Override
	public void updateHits(int boardId) throws SQLException {
		sqlMapClient.update("Board.updateHits", boardId);
	}

	@Override
	public void deleteBoard(int boardId) throws SQLException {
		sqlMapClient.delete("Board.deleteBoard", boardId);
	}

	@Override
	public BoardVO getOneBoardById(int boardId) throws SQLException {
		return (BoardVO) sqlMapClient.queryForObject("Board.getOneBoardById", boardId);
	}

	@Override
	public ArrayList<BoardVO> getBoardListByPage(int pageNo)
			throws SQLException {
		return (ArrayList<BoardVO>) sqlMapClient.queryForList("Board.getBoardListByPage", pageNo);
	}

	@Override
	public ArrayList<BoardVO> getBoardByUserId(String userId)
			throws SQLException {
		return (ArrayList<BoardVO>) sqlMapClient.queryForList("Board.getBoardByUserId", userId);
	}

	@Override
	public ArrayList<BoardVO> getBoardByTitle(String title) throws SQLException {
		return (ArrayList<BoardVO>) sqlMapClient.queryForList("Board.getBoardByTitle", title);
	}

	@Override
	public ArrayList<BoardVO> getBoardByContent(String content)
			throws SQLException {
		return (ArrayList<BoardVO>) sqlMapClient.queryForList("Board.getBoardByContent", content);
	}
	
	@Override
	public int getTotalCount() throws SQLException {
		return (int) sqlMapClient.queryForObject("Board.getTotalCount");
	}
}
